<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml"
      xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>每周四商机跟踪列表</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
          name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--插件样式-->
    <link rel="stylesheet" href="/dist/plugins/select2/select2.min.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=39cd89cd">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">
    <style>
        .table > tbody > tr > td {
            line-height: 24px;
            max-height: 24px;
            overflow: hidden;
        }

        span.lineOne {
            line-height: 28px;
            height: 28px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            /*-webkit-line-clamp: 1;*/
        }

        .div-td-content-more {
            position: absolute;
            height: auto;
            z-index: 999;
            line-height: 20px;
            background-color: #d3e8fd;
            padding: 8px 6px;
            border: 1px solid #e8e8ea;
            display: none;
        }

        .divCheck {
            height: 100%;
            margin-left: 5px;
            line-height: 25px;
        }

        .divCheck input {
            float: left;
            margin-top: 7px;
            margin-right: 5px;
        }

        .div-td-content-more i {
            width: 15px;
            height: 12px;
            background: url("/dist/img/more-icon.png");
            position: absolute;
            left: 20px;
            top: -12px;
        }

        .left {
            width: 170px;
            float: left;
        }

        .right {
            margin-left: 180px;
        }

        .input-sm {
            height: 30px;
        }

        /*.templateStyle {*/
        /*border: 1px solid #ddd;*/
        /*padding: 0 10px;*/
        /*}*/
    </style>
</head>
<body>
<section class="content" id="app" v-cloak>
    <div class="div-td-content-more"><i></i></div>
    <div class="row">
        <div>
            <div class="templateStyle iframeH" style="overflow-y: auto;">
                <div style="height: 35px;display: flex;margin-bottom: 5px">
                    <input type="text" placeholder="关键字" class="form-control input-sm"
                           style="flex: 1;" v-model="searchParams.key">
                    <button type="button" class="btn oaBtn btn-sm"
                            style="width:50px;margin-left: 10px;height: 30px;" @click="search">查询
                    </button>
                    <button v-if="roleName=='区域经理'" type="button"
                            style="height: 30px;margin-left: 10px;"
                            class="btn oaBtn btn-sm" @click="trackBtn">
                        新增商机
                    </button>
                </div>
                <div class="box-body no-padding iframeH" style="overflow: auto;" id="scrollDiv">
                    <table class="table table-bordered text-center table-striped" style="table-layout: auto">
                        <thead>
                        <tr>
                            <th v-if="roleName!='区域经理'" style="width: 65px">区域经理</th>
                            <th style="width: 61px">客户姓名</th>
                            <!--<th style="width: 70px">客户电话</th>-->
                            <!--<th style="width: 65px">客户所在地</th>-->
                            <th style="width: 65px">商机状态</th>
                            <!--<th style="width: 93px">商机确认日期</th>-->
                            <!--<th style="width: 75px">购机方式</th>-->
                            <th style="width: 55px">需求机型</th>
                            <!--<th style="width: 61px">需求台量</th>-->
                            <th style="width: 55px">报价</th>
                            <!--<th>工况</th>-->
                            <th style="width: 90px">当前状态</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr v-for="(item,i) in list">
                            <td v-if="roleName!='区域经理'">{{item.regionalManagerName}}</td>
                            <td>
                                <span v-if="(item.auditFlag==-1||item.auditFlag==2) && item.regionalManagerId==userId"
                                      style="color:#2a8cec;cursor: pointer;"
                                      @click="goDetail('edit',item)">{{item.customerName}}</span>
                                <span v-else-if="(item.auditFlag==0 && userId==item.currentAuditorId)"
                                      style="color:#2a8cec;cursor: pointer;"
                                      @click="goDetail('audit',item)">{{item.customerName}}</span>
                                <span v-else style="color:#2a8cec;cursor: pointer;"
                                      @click="goDetail('look',item)">{{item.customerName}}</span>
                            </td>
                            <!--<td>{{item.customerTel}}</td>-->
                            <!--<td><span class="lineOne">{{item.customerAddress}}</span></td>-->
                            <td><span class="lineOne">{{delEn(item.confirmationStatus)}}</span></td>
                            <!--<td>{{item.confirmationDate}}</td>-->
                            <!--<td>{{item.buyType}}</td>-->
                            <td><span class="lineOne">{{item.needModel}}</span></td>
                            <!--<td>{{item.needNumber}}台</td>-->
                            <td><span class="lineOne">{{item.dealerquote}}万元</span></td>
                            <!--<td class="lineOne">{{item.buildCondition}}</td>-->
                            <td>
                                <span v-if="(item.auditFlag==0 && userId==item.currentAuditorId) || item.auditFlag==2"
                                      class="lineOne" style="color:red;">{{convertAuditFlagToName(item)}}</span>
                                <span v-else class="lineOne">{{convertAuditFlagToName(item)}}</span>
                            </td>
                            <!--<td v-if="userId==item.regionalManagerId && item.auditFlag=='-1'">-->
                            <!--<a href="javascript:void(0);" @click="goDetail('edit',i)">&nbsp;编辑&nbsp;</a>-->
                            <!--</td>-->
                            <!--<td v-else-if="userId==item.regionalManagerId && item.auditFlag=='2' ">-->
                            <!--<a href="javascript:void(0);" @click="goDetail('edit',i)">&nbsp;重新编辑&nbsp;</a>-->
                            <!--</td>-->
                            <!--<td v-else-if="userId==item.currentAuditorId && item.auditFlag=='0'">-->
                            <!--<a href="javascript:void(0);" @click="goDetail('audit',i)">&nbsp;审核&nbsp;</a>-->
                            <!--</td>-->
                            <!--<td v-else>-->
                            <!--<a href="javascript:void(0);" @click="goDetail('look',i)">&nbsp;查看&nbsp;</a>-->
                            <!--</td>-->
                        </tr>
                        </tbody>
                    </table>
                    <div class="oa-pager text-center" style="margin-top: 5px;">
                        共
                        <span id="allCount"> 0 </span>条记录&nbsp;&nbsp;&nbsp;
                        <span id="nowPage"> 1 </span>/<span id="allPage">1</span>&nbsp;&nbsp;&nbsp;
                        <span class="oa-pager-button" id="first">首页</span>
                        <span class="oa-pager-button" id="prev">上一页</span>
                        <span class="oa-pager-button" id="next">下一页</span>
                        <span class="oa-pager-button" id="last">尾页</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=7e54a132"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oaApp.js"></script>
<!--插件JS-->
<script src="/dist/plugins/scroll/myScroll.js"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript" src="/dist/plugins/My97DatePicker/WdatePicker.js"></script>
<script>
    $.ajaxSetup({
        global: true,
        type: "POST",
        cache: false,
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        beforeSend: function () {
        },
        complete: function () {

        },
        error: function (e) {
            alert('error' + e.responseText);
        }
    });
    $.extend($.wyui, {
        page: {
            urlParams: null,
            queryParams: {
                requestPage: 1,
                pageSize: 30
            },
            dataUrl: '',
            getByPage_callback: null,
            createQueryParams: function () {
            },
            getByPage: function (type) {
                if (type == "scroll") {
                    $.wyui.page.queryParams.requestPage++;
                }
                $.ajax({
                    url: $.wyui.page.dataUrl,
                    data: JSON.stringify($.wyui.page.queryParams),
                    beforeSend: function () {

                    },
                    complete: function () {
                    },
                    success: function (r) {
                        $("#allCount").html(r.data.sendData.pager.recordCount);
                        $("#nowPage").html($.wyui.page.queryParams.requestPage);
                        if (r.data.sendData.pager.pageCount == 0) {
                            r.data.sendData.pager.pageCount = 1;
                        }
                        $("#allPage").html(r.data.sendData.pager.pageCount);
                        if (type == "scroll") {
                            $.wyui.page.getByPage_scroll_callback(r.data.sendData.records);
                        } else {
                            $.wyui.page.getByPage_callback(r.data.sendData.records);
                            if ($.wyui.page.getByPage_callback_new) {
                                $.wyui.page.getByPage_callback_new(r.data.sendData);
                            }
                        }

                    }
                });
            }
        },
        postMethod: function (url, data, callback, sync, id) {
            if (!id) {
                id = "#app"
            }
            $.ajax({
                url: server.ip + url,
                async: sync ? false : true,
                data: JSON.stringify(data),
                beforeSend: function () {

                },
                complete: function () {
                    setTimeout(function () {
                    }, 1000);

                },
                success: function (r) {
                    if (!r.e.code) {
                        callback(r.data.sendData);
                    } else {
                        alert(r.e.desc);
                    }
                },
                error: function (e) {
                    alert(url + e.responseText);
                }
            });
        },
    });
</script>
<script>
    $(function () {
        $("body").on("click", ".lineOne", function (e) {
            if ($(".div-td-content-more").is(":hidden")) {
                var text = $(this).text();
                if (text != "") {
                    text = "<i></i>" + text;
                    $(".div-td-content-more").html(text).css({
                        "width": $(this).outerWidth() + "px",
                        "left": $(this).offset().left,
                        "top": ($(this).offset().top + $(this).outerHeight()) + "px"
                    }).show();
                    e.stopPropagation();
                }
            } else {
                $(".div-td-content-more").hide();
            }
        });
        $("body").on("click", ".div-td-content-more", function (e) {
            e.stopPropagation();
        });
        $("body").on("click", function () {
            $(".div-td-content-more").hide();
        });
    });
</script>
<script type="text/javascript">

    var app = new Vue({
        el: '#app',
        data: {
            list: [],
            roleName: getUrlParamObj().roleName,
            userId: getUrlParamObj().userId,
            searchParams: {
                key: '',
                customerName: '',
                companyId: '',
                bigRegionalId: '',
                regionalManagerId: '',
                date: new Date().Format("yyyy-MM-dd"),
            },
        },
        methods: {
            delEn: function (str) {
                var reg = /[a-zA-Z]/g;
                return str.replace(reg, "");
            },
            isShowBtn: function (eName) {
                if (($.inArray(eName, this.rightOp) > -1)) {
                    return true;
                } else {
                    return false;
                }
            },
            fmoney: function (s, n) {
                n = n > 0 && n <= 20 ? n : 2;
                s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
                var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1],
                    t = "";
                for (i = 0; i < l.length; i++) {
                    t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
                }
                return t.split("").reverse().join("") + "." + r;
            },
            //新建
            trackBtn: function () {
                var obj = {
                    type: 'goDetail',
                    url: '/reportForm/salesForecastReport/thursdayTrackApp.html?' +
                        'id=' +
                        "&pageType=edit" +
                        "&userId=" + getUrlParamObj().userId +
                        "&userName=" + getUrlParamObj().userName +
                        "&roleName=" + getUrlParamObj().roleName +
                        "&companyId=" + getUrlParamObj().companyId +
                        "&companyName=" + getUrlParamObj().companyName +
                        "&departId=" + getUrlParamObj().departId,
                    id: '',
                    name: "新增商机",
                }
                prompt(JSON.stringify(obj))
            },
            //跳转页  编辑和查看
            goDetail: function (type, item) {
                var obj = {
                    type: 'goDetail',
                    url: '/reportForm/salesForecastReport/thursdayTrackApp.html?' +
                        'id=' + item.id +
                        "&pageType=" + type +
                        "&userId=" + getUrlParamObj().userId +
                        "&userName=" + getUrlParamObj().userName +
                        "&roleName=" + getUrlParamObj().roleName +
                        "&companyId=" + getUrlParamObj().companyId +
                        "&companyName=" + getUrlParamObj().companyName +
                        "&departId=" + getUrlParamObj().departId,
                    id: item.id,
                    name: "商机跟踪",
                }
                prompt(JSON.stringify(obj))
            },
            //列表页
            getThurTrackList: function () {
                var that = this;
                var dialog = {
                    dialog: 'show'
                }
                prompt(JSON.stringify(dialog))
                $.wyui.page.dataUrl = server.ip + urlConfig.thursday.getThurTrackList;
                var obj = {
                    key: that.searchParams.key,
                    userId: that.userId,
                    companyId: that.searchParams.companyId,
                    bigRegionalId: that.searchParams.bigRegionalId,
                    regionalManagerId: that.searchParams.regionalManagerId,
                    dateTime: that.searchParams.date
                }
                $.extend($.wyui.page.queryParams, obj);
                $.wyui.page.getByPage_callback = function (r) {
                    var dialog = {
                        dialog: 'hidden'
                    }
                    prompt(JSON.stringify(dialog))
                    that.list = r;
                    document.getElementById("scrollDiv").scrollTop = 0;
                };
                $.wyui.page.getByPage_scroll_callback = function (list) {
                    if (list.length < 30) {
                        isLoad = false;
                    } else {
                        for (var i = 0; i < list.length; i++) {
                            that.list.push(list[i]);
                        }
                        isLoad = true;
                    }
                };
                $.wyui.page.getByPage();
            },
            convertAuditFlagToName: function (item) {
                switch (Number(item.auditFlag)) {
                    case -1:
                        return "未提交";
                        break;
                    case 0:
                        return "待-" + item.currentAuditorName + "-审核";
                        break;
                    case 1:
                        return "已通过";
                        break;
                    case 2:
                        return "已驳回";
                        break;
                    default :
                        break;
                }
            },
            //查询方法
            search: function () {
                $.wyui.page.queryParams.requestPage = 1;
                $.extend($.wyui.page.queryParams, this.searchParams);
                this.getThurTrackList()
            },
            goClick: function (type) {
                var that = this;
                if (type == 'tiJiao') {
                    that.save(0);
                } else if (type == 'tongGuo') {
                    if (!confirm("确定要通过吗？")) {
                        return;
                    }
                    advise = '同意！';
                    $.wyui.postMethod(urlConfig.yuce.applyAudit, {
                            id: that.main.id,
                            auditFlag: 1,
                            advise: '同意!',
                            userId: that.list.userId
                        },
                        function (r) {
                            top.refreshTabByName("每周四商机跟踪详情页", "no");
                            top.closeTabByPageId("xsyc");
                        })
                    ;
                } else {
                    that.copierReturn();
                    return;
                }
            },
            //获取公司树
            getCompanyTree: function () {
                var that = this;
                $.wyui.postMethod(urlConfig.system.system.getCompanyTree, {
                    companyId: getUrlParamObj().companyId
                }, function (nodes) {
                    console.log(nodes)
                    for (var i = 0; i < nodes.length; i++) {
                        if (nodes[i].name == '重庆迎风') {
                            nodes.splice(i, 1);
                        }
                    }
                    that.searchParams.companyId = '';
                    app.searchParams.bigRegionalId = '';
                    app.searchParams.regionalManagerId = '';
                    that.getThurTrackList();
                })
            }
        },
        mounted: function () {
            $(".oa-pager-button").click(function () {
                var allPage = parseInt($("#allPage").html());
                switch (this.id) {
                    case "first":
                        $.wyui.page.queryParams.requestPage = 1;
                        break;
                    case "next":
                        $.wyui.page.queryParams.requestPage++;
                        break;
                    case "prev":
                        $.wyui.page.queryParams.requestPage--;
                        break;
                    case "last":
                        $.wyui.page.queryParams.requestPage = allPage;
                        break;
                    default:
                        break;
                }
                if ($.wyui.page.queryParams.requestPage == 0) {
                    $.wyui.page.queryParams.requestPage = 1;
                } else if ($.wyui.page.queryParams.requestPage > allPage) {
                    $.wyui.page.queryParams.requestPage = allPage;
                }
                $.wyui.page.getByPage();
            });

            var that = this;
            if (getUrlParamObj().roleName == '区域经理') {
                that.searchParams.companyId = '';
                that.searchParams.bigRegionalId = '';
                that.searchParams.regionalManagerId = that.userId;
                that.getThurTrackList();
            }
            else if (getUrlParamObj().roleName == '大区经理') {
                that.isDaQuJingLi = true
                that.searchParams.companyId = '';
                that.searchParams.regionalManagerId = ''
                that.searchParams.bigRegionalId = getUrlParamObj().departId;
                console.log("1")
                that.getThurTrackList();
            } else {
                //查询公司
                that.getCompanyTree();
            }
        }
    });


    $.wyui.page.dataUrl = server.ip + urlConfig.thursday.getThurTrackList;
    $.extend($.wyui.page.queryParams, app.searchParams);
    // $.wyui.page.getByPage()
    $.wyui.page.getByPage_callback = function (records) {
        console.log(records)
        var dialog = {
            dialog: 'hidden'
        }
        prompt(JSON.stringify(dialog))
        app.list = records;
        document.getElementById("scrollDiv").scrollTop = 0;
    };
    $.wyui.page.getByPage_scroll_callback = function (list) {
        if (list.length < 30) {
            isLoad = false;
        } else {
            for (var i = 0; i < list.length; i++) {
                app.list.push(list[i]);
            }
            isLoad = true;
        }
    }

</script>
<script>
    /************************滚动加载******************************/
    var divscroll = document.getElementById('scrollDiv');

    function divScroll() {
        var wholeHeight = divscroll.scrollHeight;
        var scrollTop = divscroll.scrollTop;
        var divHeight = divscroll.clientHeight;
        console.log(scrollTop + divHeight, wholeHeight)
        if (scrollTop + divHeight >= wholeHeight - 2) {
//            alert('滚动到底部了！');
            if (isLoad) {
                isLoad = false;
                setTimeout($.wyui.page.getByPage("scroll"), 1000);

            }

            //这里写动态加载的逻辑，比如Ajax请求后端返回下一个页面的内容
        }

    }

    divscroll.onscroll = divScroll;
</script>
</body>
</html>